var xheList;
var ViewType = eCharts.typeDesc;


const ViewStatus = [
    { "key": "1", "value": "已发布", "defaulted": "true" },
    { "key": "0", "value": "已作废" }
];

$(function () {

    Template.init("temp");

    bind();
    search();
});

var bind = function () {
    try {
        OptionUtil.bind("ddl_S_ViewType", "key", "value", eCharts.typeDesc, false, null, "");
    }
    catch (e) { }
}

var init = function () {

    xheList = new XheList();
    //_SearchModel.Methed = "DataCenterGet_1_0";
    xheList.model.TableID = "tbl_Data";
    xheList.model.ModalID = "div_Modal";
    xheList.model.Title = "";
    xheList.model.Table = "t_data_view";
    xheList.model.SortName = "viewcode";
    xheList.model.PrimaryKey = "viewcode";
    xheList.model.Button.Show = "详情";
    xheList.model.Button.Info = "预览";
    xheList.model.Checked = false;
    xheList.model.Number = true;
};

// 展示列表数据
var search = function () {

    try {
        init();

        xheList.model.Columns = [
            ["viewname", "数据集名称", "15", "", "C", "", true],
            ["viewtype", "展现类型", "6", "", "C", ViewType, true],
            ["releaseperson", "发布人", "6", "", "C", "", true],
            ["releasetime", "发布时间", "10", "", "C", "", true],
            ["status", "状态", "10", "", "C", ViewStatus, true],
            ["viewcode", "操作", "8", "null", "I", "", true]
        ];

        xheList.search();
    } catch (e) {
        alert(e);
    }
};


var info = function (model, value, row, index) {
    try {


        $('#div_Info').modal('show');

        setTimeout(bindInfo, 1, row);

    }
    catch (e) {
        alert(e);
    }
};

var bindInfo = function (row) {
    try {
        var vXheList = new XheList();
        vXheList.model.Methed = "PerfectUIGet_1_0";
        vXheList.model.Table = "t_data_view";
        vXheList.model.Filter = [
            ["viewcode", "A", "EQ", "I", row.viewcode]
        ];

        let vResult = vXheList.query();
        let chart = new xheCharts();

        chart.options.type = row.viewtype;
        chart.options.titleText = "";
        chart.options.titleSize = 18;
        chart.options.tooltipShow = true;
        chart.options.tooltipFormatter = "{b}:\n{c}条，占{d}%";

        if (row.viewtype == "Pie") {
            chart.options.center = [['50%', '60%']];
            chart.options.data = [vResult.data];
        }
        else if (row.viewtype == "Table") {

        }
        else {
            chart.options.legendGroup = vResult.legendGroup;
            chart.options.data = vResult.data;
        }

        chart.options.control = "div_view_info";
        chart.load();
    }
    catch (e) {
        alert(e);
    }
}

function formatColumn(value) {

    let vResult = "";

    try {
        if (value != "") {
            let aryColumns = String(value).split(",");

            for (let i = 0; i < aryColumns.length; i++) {
                let vKey = String(aryColumns[i]).split(":")[0];
                let vValue = String(aryColumns[i]).split(":")[1];

                vResult += vValue + ",";
            }

            vResult = vResult.substr(0, vResult.length - 1);
        }
    }
    catch (e) {
        vResult = value;
    }

    return vResult;
}













